Skip to content

allow HTTPClient to handle large payloads, in case the client (such as WifiClientSecure) does not #6969

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

r-downing
Copy link
Contributor

Description of Change

WiFiClient handles large write() by breaking it down and sending the whole thing in pieces, but WiFiClientSecure may just do a partial send and return the partial size, causing this to fail and return HTTPC_ERROR_SEND_PAYLOAD_FAILED

Tests scenarios

I have tested this successfully on an ESP32-S2 by posting a large jpeg file to an https server successfully.

…ase the client (such as WifiClientSecure) does not
@CLAassistant
Copy link

CLAassistant commented Jul 11, 2022

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

size_t totalSent = 0;
while(_client->connected() && (totalSent < size))
{
totalSent += _client->write(&payload[totalSent], (size - totalSent));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if write returns 0 and client is still connected, that would mean that the socket is not ready to be written to. I suggest you catch this situation and delay a bit before retrying. Currently the code will try in a busy loop and on single core chips (or when code runs on the same core and WiFi) this is not a good idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like this?

Suggested change
totalSent += _client->write(&payload[totalSent], (size - totalSent));
const size_t thisSend = _client->write(&payload[totalSent], (size - totalSent));
totalSent += thisSend;
if(thisSend == 0) {
delay(10);
}

Should we add a delay? Or just bail out if write returns 0? I can't remember, but maybe I thought client->write was blocking?

@PilnyTomas
Copy link
Contributor

@r-downing thank you for your contribution!
Could you please provide a simple example demonstrating the fixed and unfixed state?

@r-downing
Copy link
Contributor Author

@r-downing thank you for your contribution! Could you please provide a simple example demonstrating the fixed and unfixed state?

I don't currently have access to the code or hardware I was working on when I encountered the issue originally, but I could try to generate a quick example if needed.

Basically in any case where you send a large payload (1000's of bytes) with HTTPClient and WifiClientSecure it will get cut off.

@PilnyTomas
Copy link
Contributor

if needed

Yes, please.

@VojtechBartoska VojtechBartoska added this to the 3.0.0-RC1 milestone Nov 28, 2023
@VojtechBartoska VojtechBartoska added the Status: Review needed Issue or PR is awaiting review label Nov 28, 2023
@me-no-dev
Copy link
Member

Closing because already implemented here: #8006

@me-no-dev me-no-dev closed this Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Review needed Issue or PR is awaiting review
Projects
Development

Successfully merging this pull request may close these issues.

5 participants